home *** CD-ROM | disk | FTP | other *** search
- ;RAMFREE
- ;determine amount of available RAM without using CHKDSK
- ;Kim Kokkonen, TurboPower Software, 6/85, 408-378-3672
- ;written for CHeap ASseMbler
- ;Microsoft assembler requires minor modifications
- ;only works for up to 640K bytes
- ;
- ramfree proc far
-
- ;shrink memory available to this program
- mov ah,4AH
- mov bx,offset(theend)
- mov cl,4
- shr bx,cl ;convert bytes to paragraphs
- inc bx ;round up to be safe
- int 21H ;DOS SETBLOCK function
-
- ;try to allocate the maximum memory
- mov ah,4AH
- mov bx,FFFFH
- int 21H ;use SETBLOCK again
- ;BX contains number of paragraphs available
-
- ;convert paragraphs to a doubleword number of bytes in dx:ax
- mov ax,bx
- xor dx,dx
- mov dl,ah ;dl will contain top four bytes of ah
- mov cl,4
- shr dx,cl
- shl ax,cl
-
- ;convert doubleword to a six char ASCII number
- mov bx,offset(nbyts)
- mov cx,6
- filbuf movb [bx],' ' ;guarantee 6 spaces in nbytes
- inc bx ;set up bx to point to last char in string
- loop filbuf
-
- mov si,10 ;prepare to divide by 10
- nexdgt div ax,si ;divide dx:ax by si
- or dx,30H ;convert remainder to ASCII digit
- dec bx ;backup in buffer
- mov [bx],dl ;store character
- xor dx,dx ;clear remainder
- or ax,ax ;all done?
- jnz nexdgt ;do next digit
-
- ;now output the string
- mov dx,offset(bmess$)
- mov ah,09H
- int 21H ;print string
-
- ;exit
- int 20H
-
-
- ;data area
- bmess$ db 13,10,'RAM bytes available: '
- nbyts db 0,0,0,0,0,0,13,10,36 ;will hold ASCII number of bytes
-
- theend endp